package com.luo.service;

import com.luo.mapper.DriverMapper;
import com.luo.pojo.Department;
import com.luo.pojo.Driver;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DriverService {

    @Resource
    private DriverMapper driverMapper;

    public Map<String,Object> selectDriverList(String username,String phone,
                                               String driverCard,String driverType,
                                               int page,int limit){
        Map<String, Object> map = new HashMap<>();
        int index = (page-1)*limit;
        List<Driver> drivers = driverMapper.selectDriverList(username,phone, driverCard,driverType,index,limit);
        map.put("code", 0);
        map.put("msg", "");
        map.put("data", drivers);
        return map;
    }

    public Map<String,Object> delete(Integer id){
        Map<String,Object> map = new HashMap<>();
        driverMapper.delete(id);
        map.put("code", 200);
        map.put("msg", "删除驾驶员成功");
        map.put("data", "");
        return map;
    }

    public Map<String,Object> insert(Driver driver){
        Map<String,Object> map = new HashMap<>();
        driverMapper.insert(driver);
        map.put("code", 200);
        map.put("msg", "添加驾驶员成功");
        map.put("data", "");
        return map;
    }

    public Map<String,Object> update(Driver driver){
        Map<String,Object> map = new HashMap<>();
        driverMapper.update(driver);
        map.put("code", 200);
        map.put("msg", "更新驾驶员成功");
        map.put("data", driver);
        return map;
    }

}
